<?php $this->headTitle("Promotions") ?>

<h4>Promotions</h4>
<div class="block" style="padding-top: 10px">
    <p><strong>A toi de dire ce que tu veux comme texte, j'adapterai...</strong></p>
    <?php if ($this->discounts) : ?>
    <p>Voici les promotions que nous pratiquons pour le moment :</p>

    <div id="grid-container">
        <table cellpadding="0" cellspacing="0" border="0" class="display" id="discount-grid" width="100%">
            <thead>
            <tr>
                <th style="width: 150px;"></th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($this->discounts as $index => $discount): ?>
                <?php if (file_exists(realpath(Application::getCarouselPicturesPath() . '/discount/' . $discount['id'] . '.jpg'))) : ?>
                    <tr class="<?php echo ($index %2) ? 'even' : 'odd'?>">
                        <td>
                            <?php $thumbnailPath = Application::getCarouselPicturesPath(true) . 'discount/thumbs/' . $discount['id'] . '.jpg' ?>
                            <?php $imagePath = Application::getCarouselPicturesPath(true) . 'discount/' . $discount['id'] . '.jpg' ?>
                            <img class="img-polaroid pointer modal-toggler" data="<?php echo $discount['id'] ?>" src="<?php echo $thumbnailPath ?>" alt="Promotion" title="Détail de la promotion"/>
                            <div id="myModal_<?php echo $discount['id'] ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h3 id="myModalLabel">Détails de la promotion</h3>
                                </div>
                                <div class="modal-body">
                                    <p><img src="<?php echo $imagePath ?>"</p>
                                </div>
                                <div class="modal-footer">
                                    <button class="btn" data-dismiss="modal" aria-hidden="true">Fermer</button>
                                </div>
                            </div>
                        </td>
                        <td><?php echo $discount['item_text'] ?></td>
                    </tr>
                <?php endif ?>
            <?php endforeach ?>
            </tbody>
        </table>
    </div>

    <script>
        $(document).ready(function () {
            gridInFrench('#discount-grid');
        });

        $('.modal-toggler').click(function (e){
            var id = e.srcElement.attributes['data'].value;
            $('#myModal_' + id).modal();

        });

        /*
        $('.img-polaroid').popover({
            html: true,
            trigger: 'click',
            placement: 'right'
        });
        */
    </script>

    <style>
        div.popover {
            max-width: inherit !important;
        }
    </style>

    <?php else : ?>
    <p>Il n'y aucune promotion à vous proposer pour le moment, revenez bientôt</p>
    <?php endif ?>
</div>